package com.storage.view.container
{
	import flash.events.MouseEvent;
	
	import mx.containers.HBox;
	import mx.containers.Panel;
	import mx.controls.LinkButton;
	import mx.effects.Resize;
	import mx.events.EffectEvent;

	public class MenuPanel extends Panel
	{
		
		
		private var controlsHolder:HBox;			//按钮容器
		private var resizeButton:LinkButton;
		
		[Bindable]
		private var linkLabel:String = "<<";
		
		
		private var _panelState:String ;
		
		public static var  SAMLL_STATE:String = 'small';
		public static var  NORMAL_STATE:String = 'normal';
		public function MenuPanel()
		{
			super();
		}
		
		override protected function createChildren():void{
			super.createChildren();
			
			controlsHolder  = new HBox();//创建放置按钮的容器
			controlsHolder.setStyle("paddingRight", getStyle("paddingRight"));
			controlsHolder.setStyle("paddingLeft", getStyle("paddingLeft"));
			controlsHolder.setStyle("horizontalAlign", "right");
			controlsHolder.setStyle("verticalAlign", "middle");
			controlsHolder.setStyle("horizontalGap", 3);
			
			resizeButton = new LinkButton();
			resizeButton.height = 14;
			resizeButton.width = 18;
			//BindingUtils.bindProperty(resizeButton,'label',linkLabel);
			resizeButton.label = linkLabel;
			resizeButton.addEventListener(MouseEvent.CLICK,onResizeHandler);
			controlsHolder.addChild(resizeButton);
			//titleBar.addChild(controlsHolder);
			rawChildren.addChild(controlsHolder);//添加到原children
			_panelState = NORMAL_STATE;
			
		}
		
		private function onResizeHandler(event:MouseEvent):void{
			//正常情况下
			if(_panelState==NORMAL_STATE){
				var e:Resize = new Resize();
				e.duration = 500;
				e.target = this;
				e.widthFrom = this.width;
				e.widthTo = 0;
				e.addEventListener(EffectEvent.EFFECT_END,function():void{
						linkLabel = ">>";
						_panelState = SAMLL_STATE;
				});
				e.play();
				
			
			//最小情况下	
			}else if(_panelState==SAMLL_STATE){
				var r:Resize = new Resize();
				r.duration = 500;
				r.target = this;
				r.widthFrom = 0;
				r.widthTo = this.width;
				r.addEventListener(EffectEvent.EFFECT_END,function():void{
						linkLabel = "<<";
						_panelState = NORMAL_STATE;
				});
				r.play();
			}
			
		}
	}
}